home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / utilsys / uptime.lha / uptime.c < prev   
C/C++ Source or Header  |  1996-04-11  |  1KB  |  45 lines

  1. #include <stdio.h>
  2. #include <time.h>
  3. main(int argc,char *argv[])
  4. {
  5.     FILE *fp;
  6.     char tmp[40],up[40];
  7.     int now,then,sec,min,hour,day,diff;
  8.     if((fp=fopen("t:uupat","r"))==NULL) setup(argv[0]);
  9.     fscanf(fp,"%d",up);
  10.     fseek(fp,0,SEEK_SET);
  11.     fscanf(fp,"%d",&then);
  12.     fclose(fp);
  13.     ucase(argv[0]);
  14.     printf("%c%c%c%c%c%s ",0x1b,0x5b,0x33,0x32,0x6d,argv[0]);
  15.     printf("%c%c%c%cby ",0x1b,0x5b,0x30,0x6d);
  16.     printf("%c%c%c%c%cJim Ahrens\n\n",0x1b,0x5b,0x33,0x33,0x6d);
  17.     printf(" %c%c%c%csystem booted at : %s ",0x1b,0x5b,0x30,0x6d,ctime(up));
  18.     now=time(tmp);
  19.     printf("the current time : %s ",ctime(tmp));
  20.     diff=now-then; day=diff/(60*60*24); diff-=day*(60*60*24); 
  21.     hour=diff/(60*60); diff-=hour*(60*60); min=diff/60; sec=diff-(min*60);
  22.     printf("The System has been up for ");
  23.     if(day) printf("%d days ",day);
  24.     if(hour) printf("%d hours ",hour);
  25.     if(min)
  26.         {
  27.             printf("%d minutes and %d seconds\n\n",min,sec);
  28.             exit(0);
  29.         }
  30.     printf("%d seconds\n",sec);
  31.     exit(0);
  32. }
  33. setup(name)
  34. char name[40];
  35. {
  36.     FILE *fp;
  37.     char tmp[40];
  38.     fp=fopen("t:uupat","w");
  39.     fprintf(fp,"%d",time(tmp));
  40.     fprintf(fp,"This file is needed by %s DO NOT REMOVE IT!\n",name);
  41.     fprintf(fp,"%s by Jim Ahrens © 1992-1993\n",name);
  42.     fclose(fp);
  43.     exit(0);
  44. }
  45.